﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace lcps.Web.article
{
    public partial class Modify : Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int id = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(id);
                }
            }
        }

        private void ShowInfo(int id)
        {
            lcps.BLL.article bll = new lcps.BLL.article();
            lcps.Model.article model = bll.GetModel(id);
            this.lblid.Text = model.id.ToString();
            this.txttitle.Text = model.title;
            this.txtcontent.Text = model.content;
            this.ddl_type.SelectedValue = model.contentType;
            this.txtpubtime.Text = model.pubtime.ToString();
            this.txtimgurl.Text = model.imgurl;

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txttitle.Text.Trim().Length == 0)
            {
                strErr += "title不能为空！\\n";
            }
            if (this.txtcontent.Text.Trim().Length == 0)
            {
                strErr += "content不能为空！\\n";
            }
           
            if (!PageValidate.IsDateTime(txtpubtime.Text))
            {
                strErr += "pubtime格式错误！\\n";
            }
           

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int id = int.Parse(this.lblid.Text);
            string title = this.txttitle.Text;
            string content = this.txtcontent.Text;
            string contentType = this.ddl_type.SelectedItem.Value;
            DateTime pubtime = DateTime.Parse(this.txtpubtime.Text);
            string imgurl = this.txtimgurl.Text;


            lcps.Model.article model = new lcps.Model.article();
            model.id = id;
            model.title = title;
            model.content = content;
            model.contentType = contentType;
            model.pubtime = pubtime;
            model.imgurl = imgurl;

            lcps.BLL.article bll = new lcps.BLL.article();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "list.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
